import { createRouter, createWebHashHistory } from "vue-router";
const modules = import.meta.glob(`../views/**/index.vue`);
/** views 下面的以index.vue文件的均为路由界面，配置动态路由 ，包括多层嵌套 */
const regxStr=`../views(.*?)/index.vue`
const regex=new RegExp(regxStr)
const dynamicRoutes = [];
for (let url in modules) {
  let com = modules[url];
  const found = url.match(regex);
  if (found && found[1]) {
    dynamicRoutes.push({
      path: found[1],
      component: com,
    });
  }
}
export const staticRoutes = [
  { path: "/:pathMatch(.*)", component: () => import("@/views/404.vue") },
];
const routes = [
  ...dynamicRoutes,
  ...staticRoutes,
];

export const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
